package com.yidu.web.other.an;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Me {
    public static void main(String[] args) {
        testDemo("com.yidu.web.other.an.Person");
        //testOne();
    }


    public static void testDemo(String className){
        try {
            Class cls = Class.forName(className);
            Object obj= cls.newInstance();
            Method[] methods = cls.getDeclaredMethods();

            for(Method m:methods){
                if(m.getAnnotation(Liandyao.class)!=null && m.getAnnotation(Liandyao.class).value().equals("yes")){
                    try {
                        m.invoke(obj,null);
                        System.out.println("正确执行了"+m.getName());
                    } catch (InvocationTargetException e) {
                        System.err.println(m.getName()+"出错了!错误信息是:"+e.getCause().getMessage());
                    }
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
    }

    public static void testOne(){
        System.out.println("==========");
        //将src下面所有的类全部找到,然后再去查找有没有注解@Liandyao的.
        Class[] clses = Me.class.getClasses();
        for(Class cls:clses){
            Liandyao l = (Liandyao) cls.getAnnotation(Liandyao.class);

        }
    }

    /*
    //新建一个User模型.
    @Table(value="ws_user")
    class User{
        @Colum(value="user_id")
        private Integer userId ;

        @Colum(value="user_name)")
        private String userName;

    }


    select * 注解得到表名 where 注解得到列名

    */

}
